﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TransCend.DAL;

namespace TransCend.Model
{
    /// <summary>
    /// FieldAttribute 的摘要说明。
    /// </summary>
    [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, Inherited = false)]
    [Serializable]
    public class ColumnAttribute : Attribute
    {
        public ColumnAttribute() { }

        public ColumnAttribute(string columnName, DataType dataType, int length)
        {
            this.Name = columnName;
            this.DataType = dataType;
            this.Length = length;
        }

        /// <summary>
        /// 字段的数据类型
        /// </summary>
        public DataType DataType { get; set; }

        /// <summary>
        /// 字段长度，对于不需要指定长度的数据类型可以不指定
        /// </summary>
        private int _length = -1;
        public int Length
        {
            get { return _length; }
            set { _length = value; }
        }

        /// <summary>
        ///     字段对应实体类属性名称
        /// </summary>
        public string Name { get; set; }

        private string _alias = null;
        public string Alias
        {
            get { return _alias == null ? Name : _alias; }
            set { _alias = value; }
        }

        /// <summary>
        ///     字段是否可为空
        /// </summary>
        private bool _nullable = true;
        public bool Nullable
        {
            get { return _nullable; }
            set { _nullable = value; }
        }

        private bool _update = true;
        public bool Update
        {
            get { return _update; }
            set { _update = value; }
        }

        private bool _insert = true;
        public bool Insert
        {
            get { return _insert; }
            set { _insert = value; }
        }

        public object Default
        {
            set;
            get;
        }
    }
}
